package system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import common.model.po.SysWebConfig;
import common.model.response.base.Result;
import org.springframework.stereotype.Service;
import system.mapper.SysWebConfigMapper;
import system.model.converter.SysWebConfigConverter;
import system.model.request.SaveUserConfigRequest;
import system.service.SysWebConfigService;

import javax.annotation.Resource;

/**
 * 服务实现类
 *
 * @author 米泽鹏
 * @since 2023-09-15 下午 12:29
 */
@Service
public class SysWebConfigServiceImpl extends ServiceImpl<SysWebConfigMapper, SysWebConfig> implements SysWebConfigService {

	@Resource
	private SysWebConfigMapper mapper;

	@Override
	public Result<?> saveUserConfig(SaveUserConfigRequest request) {
		SysWebConfig find = lambdaQuery().eq(SysWebConfig::getUserId, request.getUserId()).one();
		SysWebConfig sysWebConfig = SysWebConfigConverter.requestToPo(request);
		if (find == null) {
			save(sysWebConfig);
		} else {
			sysWebConfig.setId(find.getId());
			sysWebConfig.updateById();
		}
		return Result.success();
	}

}
